/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/sum-root-to-leaf-numbers
   @Language: C++
   @Datetime: 19-09-04 10:41
   */

class Solution {
	int dfs(TreeNode *root, int level){
		int val = level*10+root->val;
		int left = root->left?dfs(root->left,val):0;
		int right = root->right?dfs(root->right,val):0;
		return max(left+right,val);
	}
public:
	int sumNumbers(TreeNode* root) {
		return root?dfs(root,0):0;
	}
};
